package com.sq.partner.manager.webservice;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.log4j.Logger;

import com.sq.partner.manager.common.Config;
import com.sq.partner.manager.sso.webservice.ServiceException_Exception;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.webservice.life_core.PartnerServicePortType;

public class LifeCoreClient {
	private static Logger logger = LogUtil.getLog(LifeCoreClient.class);
	private static PartnerServicePortType partnerServicePortType = null;
	static {
		try {
			String url = Config.getProp("LIFE_CORE_WEBSERVICE_URL");
			logger.info("人险核心webservice请求地址:" + url);
			// 创建WebService客户端代理工厂
			JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
			// 注册WebService接口
			factory.setServiceClass(PartnerServicePortType.class);
			// 设置WebService地址
			factory.setAddress(url);
			partnerServicePortType = (PartnerServicePortType) factory.create();
		} catch (Exception e) {
			logger.error("人险核心webservice URL 初使化失败", e);
		}
		logger.info("人险核心webservice URL 初使化成功");
	}

	/**
	 * CIC报文发送
	 * @param requestXml
	 * @return
	 * @throws ServiceException_Exception
	 */
	public static String sendToCicHealth(String requestXml)
			throws ServiceException_Exception {
		return partnerServicePortType.sendToCicHealth(requestXml);
	}

	public static void main(String[] args) throws Exception {
		String requestXml = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n"
				+ "<INSUREQRET>\n" + "  <HEAD>\n"
				+ "    <TRANSRNO>1028</TRANSRNO>\n"
				+ "    <USERNAME>PartnerSales</USERNAME>\n"
				+ "    <USERPSW>CIC95585</USERPSW>\n" + "  </HEAD>\n"
				+ "  <MAIN>\n" + "    <DEPTNO>83</DEPTNO>\n"
				+ "    <ORG_NAME>life_test</ORG_NAME>\n<GRP_CERT_TYPE>11</GRP_CERT_TYPE>" 
				+ " <GRP_CERT_NO>111</GRP_CERT_NO>  </MAIN>\n"
				+ "</INSUREQRET>";
		System.out.println(sendToCicHealth(requestXml));

	}
}
